package com.springlearn.springsourcecode.chap14;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author wtcode
 * @Description
 * @date 2025/4/5 - 15:12
 */
public class A14 {
    public static void main(String[] args) {
        Proxy proxy = new Proxy();
        Target target = new Target();
        proxy.setMethodInterceptor(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                System.out.println("before...");
                //return method.invoke(target,args);  反射调用

                // FastClass避免反射
                //return methodProxy.invoke(target,args);  // 内部无反射，结合目标用
                return methodProxy.invokeSuper(o,args);
            }
        });
        proxy.save();
        proxy.save(1);
        proxy.save(1L);
    }
}
